﻿Imports System.Data.OleDb

Partial Public Class memberprofile
    Inherits System.Web.UI.Page

    Dim conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("PlacesConnectionString").ToString())

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Response.Redirect("memberprofile.aspx?UserName=" & User.Identity.Name)
        Dim conn = New OleDbConnection(ConfigurationManager.ConnectionStrings("PlacesConnectionString").ToString())
        Dim sql As String = "SELECT * FROM UserInformation WHERE UserName = @UserName"
        conn.Open()
        Dim cmd As New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@UserName", User.Identity.Name)
        Dim dbRead As OleDbDataReader = cmd.ExecuteReader()
        While dbRead.Read
            'FirstLastNameLabel.Text = dbRead("FirstName") & " " & dbRead("LastName")
            'GenderLabel.Text = dbRead("Gender")
            'CityLabel.Text = dbRead("City")
            ' CountryLabel.Text = dbRead("Country")
            ' image_ProfileImage.ImageUrl = dbRead("ProfileImage")
            'If image_ProfileImage.ImageUrl = "Images/ProfileImages/" Then
            'image_ProfileImage.ImageUrl = "Images/ProfileImages/default.jpg"
            'End If
            'Try
            'SetLastActivity.Text = dbRead("LastActivityDate")
            'Catch ex As Exception
            'SetLastActivity.Text = DateString
            'End Try
        End While
        DetailsView1.DataBind()
        GridView1.DataBind()

        Dim myImagesHTML As String = ""
        Dim homePageStem As String = "MyImages.aspx?"
        myImagesHTML = myImagesHTML & String.Format("<A HREF = ""{0}"" style = ""color:Red;"" >{1}</A>", homePageStem & "UserName=" & User.Identity.Name, "My Images")
        PlaceHolder_MyImages.Controls.Add(New LiteralControl(myImagesHTML))

        Dim myGroupsHTML As String = ""
        Dim homePageStem1 As String = "ShowGroupsByUser.aspx?"
        myGroupsHTML = myGroupsHTML & String.Format("<A HREF = ""{0}"" style = ""color:Red; font-size:1.2em;"">{1}</A>", homePageStem1 & "UserName=" & User.Identity.Name, "My Groups")
        PlaceHolder_MyGroups.Controls.Add(New LiteralControl(myGroupsHTML))

        Dim myLocationsHTML As String = ""
        Dim homePageStem2 As String = "ShowLocationsByUser.aspx?"
        myLocationsHTML = myLocationsHTML & String.Format("<A HREF = ""{0}"" style = ""color:Red; font-size:1.2em;"">{1}</A>", homePageStem2 & "UserName=" & User.Identity.Name, "My Locations")
        PlaceHolder_myLocations.Controls.Add(New LiteralControl(myLocationsHTML))

        Dim myDiscussionsHTML As String = ""
        Dim homePageStem3 As String = "ShowDiscussionsByUser.aspx?"
        myDiscussionsHTML = myDiscussionsHTML & String.Format("<A HREF = ""{0}"" style = ""color:Red; font-size:1.2em;"">{1}</A>", homePageStem3 & "UserName=" & User.Identity.Name, "My Discussions")
        PlaceHolder_myDiscussions.Controls.Add(New LiteralControl(myDiscussionsHTML))



        If User.Identity.Name = Request.QueryString("UserName") Then
            PlaceHolder_MyImages.Visible = True
            PlaceHolder_MyGroups.Visible = True
            PlaceHolder_myLocations.Visible = True
            PlaceHolder_myDiscussions.Visible = True
        Else
            PlaceHolder_MyImages.Visible = False
            PlaceHolder_MyGroups.Visible = False
            PlaceHolder_myLocations.Visible = False
            PlaceHolder_myDiscussions.Visible = False
        End If


    End Sub

    Function getUserID() As Integer
        Dim loginName = User.Identity.Name
        Dim loginId As Integer
        Dim readLoginIdSQL As String = "SELECT UserId FROM aspnet_Users where UserName = @UserName"
        Dim cmd As New OleDbCommand(readLoginIdSQL, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@UserName", loginName)
        Dim reader As OleDbDataReader = cmd.ExecuteReader()
        reader.Read()
        loginId = (reader("UserId"))
        conn.Close()
        Return loginId

    End Function
End Class